﻿//注意：折叠面板 依赖 element 模块，否则无法进行功能性操作
layui.use('element', function () {
    var form = layui.form,
        element = layui.element,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    function learningKnowledge(url) {
        window.open(url);
    }

    var loadPageTop = '<div class="layui-row"><blockquote class="layui-elem-quote layui-bg-green">xxxxxxxx</blockquote ></div>';
    var loadPageContent = '<div class="layui-row"><video width="100%" height="100%"  controls="controls" autobuffer="autobuffer"  autoplay="autoplay" loop="loop"><source src="http://localhost:8089/1.mp4" type="video/mp4"></source></video></div>';
    $('ul li').click(function () {
        var dateStart = new Date(); //日期对bai象
        var courseId = $(this).parent().parent().find('input[name="courseId"]').val();
        var courseType = $(this).parent().parent().find('.courseType').val();
        var courseFileId = $(this).parent().parent().find('.courseFileId').val();
        var courseExamId = $(this).parent().parent().find('.courseExamId').val();
        var courseExamName = $(this).parent().parent().find('.courseExamName').val();
        var coursePath = $(this).parent().parent().find('.courseFile').val();
        var courseFileType = $(this).parent().parent().find('.courseFileType').val();
        var courseFileName = $(this).parent().parent().find('.courseFileName').val();
        var courseRequiredTime = $(this).parent().parent().find('.courseRequiredTime').val();
        var courseCategory = $(this).parent().parent().find('.courseCategory').val();
        var courseTask = $(this).parent().parent().find('.courseTask').val();

        if (courseType == "0") {
            if (courseFileType == "Video") {
                layer.open({
                    type: 2,
                    area: ['90%', '90%'],
                    title: courseTask + " -- " + courseCategory + " -- " + courseFileName,
                    content: '/MyTask/ShowVideoDetail?courseFileId=' + courseFileId + "&taskId=" + $("#taskId").val() + "&courseId=" + courseId + '&courseRequiredTime=' + courseRequiredTime,
                    yes: function () {
                        alert("页面打开了");
                    },
                    end: function () {
                        var dateEnd = new Date();
                        var thisTimesTime = (Math.abs(dateEnd - dateStart) / 1000).toFixed(0);
                        $.ajax({
                            type: 'POST',
                            url: '/MyTask/UpdateProcess/',
                            data: {
                                TaskId: $("#taskId").val(),
                                CourseId: courseId,
                                timeOfThisTimes: thisTimesTime
                            },
                            dataType: "json",
                            headers: {
                                "X-CSRF-TOKEN-Gerald": $("input[name='AntiforgeryKey_Gerald']").val()
                            },
                            success: function (res) {//res为相应体,function为回调函数
                                var alertIndex;
                                if (res.ResultCode === 0) {
                                    location.reload();
                                } else if (res.ResultCode === 102) {
                                    alertIndex = layer.alert(res.ResultMsg, { icon: 5 }, function () {
                                        layer.closeAll("iframe");
                                        //刷新父页面
                                        parent.location.reload();
                                        top.layer.close(alertIndex);
                                    });
                                }
                                else {
                                    layer.alert(res.ResultMsg, { icon: 5 });
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, { icon: 5 });
                            }
                        });
                    }
                });
            } else {
                layer.open({
                    type: 2,
                    area: ['85%', '90%'],
                    title: courseTask + " -- " + courseCategory + " -- " + courseFileName,
                    anim: 1,
                    content: "/MyTask/ShowOtherDetail?courseFileId=" + courseFileId + "&taskId=" + $("#taskId").val() + "&courseId=" + courseId + '&courseRequiredTime=' + courseRequiredTime,
                    yes: function () {
                        alert("页面打开了");
                    },
                    end: function () {
                        var dateEnd = new Date();
                        var thisTimesTime = (Math.abs(dateEnd - dateStart) / 1000).toFixed(0);
                        $.ajax({
                            type: 'POST',
                            url: '/MyTask/UpdateProcess/',
                            data: {
                                TaskId: $("#taskId").val(),
                                CourseId: courseId,
                                timeOfThisTimes: thisTimesTime
                            },
                            dataType: "json",
                            headers: {
                                "X-CSRF-TOKEN-Gerald": $("input[name='AntiforgeryKey_Gerald']").val()
                            },
                            success: function (res) {//res为相应体,function为回调函数
                                var alertIndex;
                                if (res.ResultCode === 0) {
                                    location.reload();
                                    //parent.location.reload();
                                } else if (res.ResultCode === 102) {
                                    alertIndex = layer.alert(res.ResultMsg, { icon: 5 }, function () {
                                        layer.closeAll("iframe");
                                        //刷新父页面
                                        parent.location.reload();
                                        top.layer.close(alertIndex);
                                    });
                                }
                                else {
                                    layer.alert(res.ResultMsg, { icon: 5 });
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.alert('操作失败！！！' + XMLHttpRequest.status + "|" + XMLHttpRequest.readyState + "|" + textStatus, { icon: 5 });
                            }
                        });
                    }
                });
            }
        }
        else {
            layer.open({
                type: 2,
                area: ['80%', '80%'],
                title: courseTask + " -- " + courseCategory + " -- " + courseExamName,
                anim: 1,
                content: "/MyTask/ShowExamPageDetail?courseExamId=" + courseExamId + "&courseId=" + courseId + "&taskId=" + $("#taskId").val(),
                yes: function () {
                    alert("页面打开了");
                },
                end: function () {
                    location.reload();
                }
            });
        }
    })
});